package com.abso.mp3tunes.locker.ui.actions;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.abso.mp3tunes.locker.core.data.Artist;
import com.abso.mp3tunes.locker.ui.LockerImages;
import com.abso.mp3tunes.locker.ui.viewers.LockerViewer;

/**
 * Action able to open the Last.fm page associated with a specific artist.
 */
public class OpenLastFMArtistPageAction extends AbstractOpenBrowserAction {

	/** The selected artist. */
	private Artist artist;

	/**
	 * Constructs a new action.
	 * 
	 * @param lockerViewer
	 *            the Locker tree viewer.
	 */
	public OpenLastFMArtistPageAction(LockerViewer lockerViewer) {
		super("Open Last.fm Page", LockerImages.getDescriptor(LockerImages.LAST_FM),
				lockerViewer);
	}

	/**
	 * Sets the current artist.
	 * 
	 * @param artist
	 *            the selected artist.
	 */
	public void setSelectedArtist(Artist artist) {
		this.artist = artist;
	}

	/* (non-Javadoc)
	 * @see com.abso.mp3tunes.locker.ui.actions.AbstractOpenBrowserAction#getURL()
	 */
	protected String getURL() {
		try {
			return "http://www.last.fm/music/" + URLEncoder.encode(artist.getName(), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			return "http://www.last.fm/music/" + artist.getName();
		}
	}

	

}
